package com.dengcj.epl.entity;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

/**
 * @author dengchunjie
 * @Description: RestApi通用返回结果类（用于解析拿到的接口报文封装以后续使用）
 * @date 2022/4/26 15:44
 */
public class ApiResponseResult<T> {
    private boolean status;
    private String msg;
    private T data;

    public boolean success() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setSuccess(T data) {
        this.status = true;
        this.msg = "success";
        this.data = data;
    }

    public void setFailed(String msg) {
        this.status = false;
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public JSONObject getJsonData() {
        return (JSONObject) data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.set("status", this.status);
        jsonObject.set("msg", this.msg);
        jsonObject.set("data", this.data);
        return jsonObject.toString();
    }
}
